<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/corelib/kernel/qabstractitemmodel.cpp -->
<head>
  <title>Qt 4.3: QModelIndex Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QModelIndex Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
<p>The QModelIndex class is used to locate data in a data model. <a href="#details">More...</a></p>
<pre> #include &lt;QModelIndex&gt;</pre><ul>
<li><a href="qmodelindex-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qmodelindex.html#QModelIndex">QModelIndex</a></b> ()</li>
<li><div class="fn"/><b><a href="qmodelindex.html#QModelIndex-2">QModelIndex</a></b> ( const QModelIndex &amp; <i>other</i> )</li>
<li><div class="fn"/><b><a href="qmodelindex.html#dtor.QModelIndex">~QModelIndex</a></b> ()</li>
<li><div class="fn"/>QModelIndex <b><a href="qmodelindex.html#child">child</a></b> ( int <i>row</i>, int <i>column</i> ) const</li>
<li><div class="fn"/>int <b><a href="qmodelindex.html#column">column</a></b> () const</li>
<li><div class="fn"/>QVariant <b><a href="qmodelindex.html#data">data</a></b> ( int <i>role</i> = Qt::DisplayRole ) const</li>
<li><div class="fn"/>Qt::ItemFlags <b><a href="qmodelindex.html#flags">flags</a></b> () const</li>
<li><div class="fn"/>qint64 <b><a href="qmodelindex.html#internalId">internalId</a></b> () const</li>
<li><div class="fn"/>void * <b><a href="qmodelindex.html#internalPointer">internalPointer</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qmodelindex.html#isValid">isValid</a></b> () const</li>
<li><div class="fn"/>const QAbstractItemModel * <b><a href="qmodelindex.html#model">model</a></b> () const</li>
<li><div class="fn"/>QModelIndex <b><a href="qmodelindex.html#parent">parent</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qmodelindex.html#row">row</a></b> () const</li>
<li><div class="fn"/>QModelIndex <b><a href="qmodelindex.html#sibling">sibling</a></b> ( int <i>row</i>, int <i>column</i> ) const</li>
<li><div class="fn"/>bool <b><a href="qmodelindex.html#operator-not-eq">operator!=</a></b> ( const QModelIndex &amp; <i>other</i> ) const</li>
<li><div class="fn"/>bool <b><a href="qmodelindex.html#operator-lt">operator&lt;</a></b> ( const QModelIndex &amp; <i>other</i> ) const</li>
<li><div class="fn"/>bool <b><a href="qmodelindex.html#operator-eq-eq">operator==</a></b> ( const QModelIndex &amp; <i>other</i> ) const</li>
</ul>
<a name="related-non-members"></a>
<h3>Related Non-Members</h3>
<ul>
<li><div class="fn"/>typedef <b><a href="qmodelindex.html#QModelIndexList-typedef">QModelIndexList</a></b></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QModelIndex class is used to locate data in a data model.</p>
<p>This class is used as an index into item models derived from <a href="qabstractitemmodel.html">QAbstractItemModel</a>. The index is used by item views, delegates, and selection models to locate an item in the model.</p>
<p>New QModelIndex objects are created by the model using the <a href="qabstractitemmodel.html#createIndex">QAbstractItemModel::createIndex</a>() function. An <i>invalid</i> model index can be constructed with the QModelIndex constructor. Invalid indexes are often used as parent indexes when referring to top-level items in a model.</p>
<p>Model indexes refer to items in models, and contain all the information required to specify their locations in those models. Each index is located in a given row and column, and may have a parent index; use <a href="qmodelindex.html#row">row</a>(), <a href="qmodelindex.html#column">column</a>(), and <a href="qmodelindex.html#parent">parent</a>() to obtain this information. Each top-level item in a model is represented by a model index that does not have a parent index - in this case, <a href="qmodelindex.html#parent">parent</a>() will return an invalid model index, equivalent to an index constructed with the zero argument form of the <a href="qmodelindex.html#QModelIndex">QModelIndex</a>() constructor.</p>
<p>To obtain a model index that refers to an existing item in a model, call <a href="qabstractitemmodel.html#index">QAbstractItemModel::index</a>() with the required row and column values, and the model index of the parent. When referring to top-level items in a model, supply <a href="qmodelindex.html#QModelIndex">QModelIndex</a>() as the parent index.</p>
<p>The <a href="qmodelindex.html#model">model</a>() function returns the model that the index references as a <a href="qabstractitemmodel.html">QAbstractItemModel</a>. The <a href="qmodelindex.html#child">child</a>() function is used to examine the items held beneath the index in the model. The <a href="qmodelindex.html#sibling">sibling</a>() function allows you to traverse items in the model on the same level as the index.</p>
<p>Model indexes can become invalid over time so they should be used immediately and then discarded. If you need to keep a model index over time use a <a href="qpersistentmodelindex.html">QPersistentModelIndex</a>.</p>
<p>See also <a href="model-view-programming.html">Model/View Programming</a>, <a href="qpersistentmodelindex.html">QPersistentModelIndex</a>, and <a href="qabstractitemmodel.html">QAbstractItemModel</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QModelIndex"></a>QModelIndex::QModelIndex ()</h3>
<p>Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid.</p>
<p>See also <a href="qmodelindex.html#isValid">isValid</a>() and <a href="qabstractitemmodel.html">QAbstractItemModel</a>.</p>
<h3 class="fn"><a name="QModelIndex-2"></a>QModelIndex::QModelIndex ( const QModelIndex &amp; <i>other</i> )</h3>
<p>Creates a new model index that is a copy of the <i>other</i> model index.</p>
<h3 class="fn"><a name="dtor.QModelIndex"></a>QModelIndex::~QModelIndex ()</h3>
<p>Destroys the model index.</p>
<h3 class="fn"><a name="child"></a>QModelIndex QModelIndex::child ( int <i>row</i>, int <i>column</i> ) const</h3>
<p>Returns the child of the model index that is stored in the given <i>row</i> and <i>column</i>.</p>
<p>See also <a href="qmodelindex.html#parent">parent</a>() and <a href="qmodelindex.html#sibling">sibling</a>().</p>
<h3 class="fn"><a name="column"></a>int QModelIndex::column () const</h3>
<p>Returns the column this model index refers to.</p>
<h3 class="fn"><a name="data"></a><a href="qvariant.html">QVariant</a> QModelIndex::data ( int <i>role</i> = Qt::DisplayRole ) const</h3>
<p>Returns the data for the given <i>role</i> for the item referred to by the index.</p>
<h3 class="fn"><a name="flags"></a><a href="qt.html#ItemFlag-enum">Qt::ItemFlags</a> QModelIndex::flags () const</h3>
<p>Returns the flags for the item referred to by the index.</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="internalId"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QModelIndex::internalId () const</h3>
<p>Returns a <tt>qint64</tt> used by the model to associate the index with the internal data structure.</p>
<p>See also <a href="qabstractitemmodel.html#createIndex">QAbstractItemModel::createIndex</a>().</p>
<h3 class="fn"><a name="internalPointer"></a>void * QModelIndex::internalPointer () const</h3>
<p>Returns a <tt>void</tt> <tt>*</tt> pointer used by the model to associate the index with the internal data structure.</p>
<p>See also <a href="qabstractitemmodel.html#createIndex">QAbstractItemModel::createIndex</a>().</p>
<h3 class="fn"><a name="isValid"></a>bool QModelIndex::isValid () const</h3>
<p>Returns true if this model index is valid; otherwise returns false. A valid index belongs to a model, and has non-negative row and column numbers.</p>
<p>See also <a href="qmodelindex.html#model">model</a>(), <a href="qmodelindex.html#row">row</a>(), and <a href="qmodelindex.html#column">column</a>().</p>
<h3 class="fn"><a name="model"></a>const <a href="qabstractitemmodel.html">QAbstractItemModel</a> * QModelIndex::model () const</h3>
<p>Returns a pointer to the model containing the item that this index refers to.</p>
<h3 class="fn"><a name="parent"></a>QModelIndex QModelIndex::parent () const</h3>
<p>Returns the parent of the model index, or <a href="qmodelindex.html#QModelIndex">QModelIndex</a>() if it has no parent.</p>
<p>See also <a href="qmodelindex.html#child">child</a>(), <a href="qmodelindex.html#sibling">sibling</a>(), and <a href="qmodelindex.html#model">model</a>().</p>
<h3 class="fn"><a name="row"></a>int QModelIndex::row () const</h3>
<p>Returns the row this model index refers to.</p>
<h3 class="fn"><a name="sibling"></a>QModelIndex QModelIndex::sibling ( int <i>row</i>, int <i>column</i> ) const</h3>
<p>Returns the sibling at <i>row</i> and <i>column</i> or an invalid <a href="qmodelindex.html">QModelIndex</a> if there is no sibling at this position.</p>
<p>See also <a href="qmodelindex.html#parent">parent</a>() and <a href="qmodelindex.html#child">child</a>().</p>
<h3 class="fn"><a name="operator-not-eq"></a>bool QModelIndex::operator!= ( const QModelIndex &amp; <i>other</i> ) const</h3>
<p>Returns true if this model index does not refer to the same location as the <i>other</i> model index; otherwise returns false.</p>
<h3 class="fn"><a name="operator-lt"></a>bool QModelIndex::operator&lt; ( const QModelIndex &amp; <i>other</i> ) const</h3>
<p>Returns true if this model index is smaller than the <i>other</i> model index; otherwise returns false.</p>
<p>This function was introduced in Qt 4.1.</p>
<h3 class="fn"><a name="operator-eq-eq"></a>bool QModelIndex::operator== ( const QModelIndex &amp; <i>other</i> ) const</h3>
<p>Returns true if this model index refers to the same location as the <i>other</i> model index; otherwise returns false. Note that all values in the model index are used when comparing with another model index.</p>
<hr />
<h2>Related Non-Members</h2>
<h3 class="fn"><a name="QModelIndexList-typedef"></a>typedef QModelIndexList</h3>
<p>Synonym for <a href="qlist.html">QList</a>&lt;<a href="qmodelindex.html">QModelIndex</a>&gt;.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
